# -*- coding: utf-8 -*-


import re
import sys
import warnings
warnings.filterwarnings("ignore")
import argparse
    
def openfile(filename):
    result = ""
    with open(filename,'r',encoding="utf-8") as f:
        result = f.read()
    return result


    
if __name__ == '__main__':
    # 配置支持的参数
    parser = argparse.ArgumentParser("生成 drawable 代码")
    parser.add_argument('--color',help="设置 drawable 背景色")
    parser.add_argument('--radius',help="设置 drawable 圆角",type=int)
    parser.add_argument('--stroke_width',help="设置 drawable 边框宽度",type=int)
    parser.add_argument('--stroke_color',help="设置 drawable 边框颜色")
    parser.add_argument('--corner_radii',help="设置圆角：floatArrayOf(左上，右上，右下，左下)")
    
    if len(sys.argv) < 2:
        print('生成 drawable 代码')
        print()
        print('\t--color: 设置 drawable 背景色')
        print('\t--radius: 设置 drawable 圆角')
        print('\t--stroke_width: 设置 drawable 边框宽度')
        print('\t--stroke_color: 设置 drawable 边框颜色')
        print('\t--corner_radii: 设置圆角：floatArrayOf(左上，右上，右下，左下)')
    else:
        # 参数解析
        args = parser.parse_args()
        drawableHelper = openfile('template/DrawableHelper.kt')
        params = ''
        if args.color:
            params += " fillColor = %s," % (args.color)
        if args.radius:
            params += " roundRadius = %s," % (args.radius)
        if args.stroke_width:
            params += " strokeWidth = %s," % (args.stroke_width)
        if args.stroke_color:
            params += " strokeColor = %s," % (args.stroke_color)
        if args.corner_radii:
            params += " cornerRadii = floatArrayOf(%s)," % (args.corner_radii)
            
        params = params[0: len(params)-1] # 去除最后的逗号
        drawableHelper = drawableHelper.replace("[params]", params)
        print(drawableHelper)
        pass
